﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Cache;
using Resto.CostControl.Core.Facade.SupplierModule.DataTransferObject;
using Resto.CostControl.Core.Domain.Query.SupplierModule;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.Core.Container;

namespace Resto.CostControl.Core.Cache
{
    internal class SupplierDTOCache : ObjectCache<SupplierDTO, SupplierDTOCache>
    {
        static SupplierDTOCache()
        {
            OnCacheObjectNotFound += FindObject;
        }

        protected override string CacheKey_Prefix
        {
            get { return "SupplierDTOCacheKey_"; }
        }

        protected override CacheMode CacheMode
        {
            get { return CacheMode.DistributedContext; }
        }

        private static void FindObject(object sender, CacheEventArgs args)
        {
            SupplierDQO supplierDQO = ObjectCreator.Create<SupplierDQO>();
            Supplier supplier = supplierDQO.GetSupplierOrDefault(args.Key);
            if (supplier != null)
            {
                args.CacheObject = new SupplierDTO(supplier);
            }
        }

        //public static SupplierDTO Get(int id)
        //{
        //    return Get(id.ToString());
        //}

        //public static void Remove(int id)
        //{
        //    Remove(id.ToString());
        //}
    }
}
